package com.ruan.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @ClassName:R
 * @Author:阮昇
 * @Description:
 * @Datetime: 2023/9/20 15:08
 **/
@Data
@NoArgsConstructor
public class R<T> {

    private int code; //返回的状态码
    private String msg; //返回的消息
    private T data; //返回的数据

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public R(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public R(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    //成功返回
    public static <T> R<T> ok() {
        return new R<T>(200, "成功", null);
    }

    public static <T> R<T> ok(String msg) {
        return new R<T>(200, msg,null);
    }

    public static <T> R<T> ok(String msg, T data) {
        return new R<T>(200, msg, data);
    }

    //失败返回
    public static <T> R<T> error() {
        return new R<T>(100, "失败", null);
    }

    public static <T> R<T> error(String msg) {
        return new R<T>(100, msg,null);
    }

    public static <T> R<T> error(String msg, T data) {
        return new R<T>(100, msg, data);
    }
}
